package org.example.guavalearn.proxy;

import org.checkerframework.checker.nullness.qual.NonNull;

import java.text.MessageFormat;
import java.util.Objects;

class ObjectUtil {

    public static String toString(@NonNull Object obj) {
        return MessageFormat.format("{0}@{1}",
                obj.getClass().getName(),
                toHex(Objects.hashCode(obj)));
    }

    public static int hashCode(@NonNull Object obj) {
        return identity(obj);
    }

    public static int identity(Object obj) {
        return System.identityHashCode(obj);
    }

    private static String toHex(int i) {
        return String.format("%x", i);
    }
}
